package com.yztc.love_travel.ui.mainservice.historyculture.presenter;

import android.util.Log;

import com.yztc.love_travel.bean.HistoryBean;
import com.yztc.love_travel.ui.mainservice.historyculture.model.IHistoryCultureModel;
import com.yztc.love_travel.ui.mainservice.historyculture.model.HistoryCultureModelImpl;
import com.yztc.love_travel.ui.mainservice.historyculture.view.IHistoryCultureView;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by My on 2016/11/28.
 */

public class HistoryCulturePresenterImpl implements IHistoryCulturePresenter {
    private IHistoryCultureModel mHistoryCultureModel;
    private IHistoryCultureView  mHistoryCultureView;

    public HistoryCulturePresenterImpl(IHistoryCultureView  mHistoryCultureView) {
        mHistoryCultureModel=new HistoryCultureModelImpl();
        this.mHistoryCultureView = mHistoryCultureView;
    }

    @Override
    public void getHistoryCultureBean(String baseUrl, final Map<String, Object> params) {
        mHistoryCultureModel.getHistoryCultureBean(baseUrl,params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<HistoryBean>() {
                    @Override
                    public void onCompleted() {
                       mHistoryCultureView.loadFinish();
                        Log.e("tag",params.toString());
                    }

                    @Override
                    public void onError(Throwable e) {
                        mHistoryCultureView.loadError();

                    }

                    @Override
                    public void onNext(HistoryBean historyBean) {
                        mHistoryCultureView.showRegionCultureData(historyBean);

                    }

                    @Override
                    public void onStart() {
                        super.onStart();
                        mHistoryCultureView.loadStart();
                    }
                });
    }
}
